!
function(l) {
        function p(a) {
        var c = ControUtils.config,
        b;
        for (b in a) a.hasOwnProperty(b) && (c[b] = a[b]);
        ControUtils.config = c;
        ControUtils.musicList = ControUtils.config.musicList || []; 
        (ControUtils.musicLength = ControUtils.musicList.length) && f("body") || (ControUtils.musicDom.listWrap.innerHTML = "<p>\u6682\u65e0\u64ad\u653e\u8bb0\u5f55...</p>");
        musicLists=ControUtils.musicList;
        ControUtils.audioDom = null;
    	ControUtils.init();
    	
    }
	
    l = l || window;
    l.SMusic = function(a) {
        p(a);
    }
} (window);

var m=null;
var firstLoad=true;
q = parseInt( - 7 * Math.random() + 9);
var ControUtils={
		config: {
            musicList: [],
            defaultVolume: .7,
            defaultIndex: q
        },
        createListDom: function() {
            var a = 0,
            c = "<ul>";
            for (a; a < ControUtils.musicLength; a++){
            	var singer="";
            	for(var m1=0;m1<ControUtils.musicList[a].ar.length;m1++){
            		singer+=(ControUtils.musicList[a].ar[m1].name+",");
                }
            	singer=singer.substring(0,(singer.length-1));
            	c += '<li class="f-toe"><strong>' + ControUtils.musicList[a].name + "</strong> -- <small>" + singer+ "</small></li>";
            }
            ControUtils.musicDom.listWrap.innerHTML = c + "</ul>"
        },
        setBuffer: function(a, c) {
        	a=document.getElementsByTagName("audio")[0];
            var b = c.parentNode.offsetWidth;
            m = setInterval(function() {
                var d = a.buffered.length;
                if (0 < d && void 0 != a.buffered) {
                    var e = a.buffered.end(d - 1) / a.duration * b;
                    c.style.width = e + "px";
                    1 > Math.abs(a.duration - a.buffered.end(d - 1)) && (c.style.width = b + "px", clearInterval(m))
                }
            },
            1E4)
        },
        resetPlayer: function(a) {
            a >= ControUtils.musicLength - 1 && (a = ControUtils.musicLength - 1);
            0 >= a && (a = 0);
            ControUtils.currentMusic = a;
            var c = ControUtils.musicList[a],
            b = ControUtils,
            d = function() {
                return b.setBuffer(this, b.musicDom.bufferProcess)
            };
            if(c==null||c==undefined){
            	c=ControUtils.musicList[0];
            }
            ControUtils.audioDom.removeEventListener("canplay", d, !1);
            clearInterval(m);
            ControUtils.musicDom.bufferProcess.style.width = "0px";
            ControUtils.musicDom.curProcess.style.width = "0px";
            ControUtils.audioDom.src = "http://music.163.com/song/media/outer/url?id="+c.id+".mp3";
            var singer="";
            var lrc=MusicUtil.getLrc(c.id);
            for(var m1=0;m1<c.ar.length;m1++){
            	singer+=(c.ar[m1].name+",");
            }
            singer=singer.substring(0,(singer.length-1));
            ControUtils.musicDom.cover.innerHTML = '<img src="' + c.al.picUrl + '" title="' + c.name + " -- " + singer + '">';
            ControUtils.musicDom.title.innerHTML = "<strong title='"+c.name+"'>" + c.name + "</strong><small title='"+singer+"'>" + singer + "</small>";
            var c = document.querySelectorAll(".m-music-list-wrap li"),
            e = 0;
            for (e; e < ControUtils.musicLength; e++) e == a ? h(c[e], "current") : g(c[e], "current");
            ControUtils.audioDom.addEventListener("canplay", d, !1);
            ControUtils.play();
            // 歌词更换
            // 点击开始方法调用lrc。start歌词方法 返回时间time
            if(lrc==undefined||lrc==null||lrc==""||undefined==lrc["lrc"]||null==lrc["lrc"]||""==lrc["lrc"]){
            	lrc={
            			lrc:{
            				lyric:"[00:00.00] "+ControUtils.musicList[a].name
            			}
            	}
            };
			$lrc.start(lrc.lrc.lyric, function(){
				return time;
			});
        },
        setVolume: function(a) {
            var c = ControUtils.musicDom.volume,
            b = c.volumeEventer.offsetHeight || 50;
            0 >= a && (a = 0);
            1 <= a && (a = 1);
            ControUtils.audioDom.volume = a;
            b *= a;
            c.volumeCurrent.style.height = b + "px";
            c.volumeCtrlBar.style.bottom = b + "px";
            c.volumeProcess.setAttribute("data-volume", a);
            0 == a ? (h(c.volumeControl, "muted"), ControUtils.audioDom.muted = !0) : (g(c.volumeControl, "muted"), ControUtils.audioDom.muted = !1)
        },
        initPlay: function() {
            var a = ControUtils.config.defaultIndex;
            if(ControUtils.config.musicList!=undefined&&ControUtils.config.musicList!=null&&ControUtils.config.musicList.length<a)a=0;
            ControUtils.setVolume(ControUtils.config.defaultVolume);
            ControUtils.audioDom.load();
            ControUtils.resetPlayer(a);
        },
        play: function() {
            var a = ControUtils.musicDom.button.ctrl;
            ControUtils.audioDom.play();
            time= ControUtils.audioDom.currentTime;
            g(a, "paused");
            h(a, "play");
            a.setAttribute("title", "\u6682\u505c");
            g(ControUtils.musicDom.cover, "paused");
            h(ControUtils.musicDom.cover, "play");
        },
        pause: function() {
            var a = ControUtils.musicDom.button.ctrl;
            ControUtils.audioDom.pause();
            g(a, "play");
            h(a, "paused");
            a.setAttribute("title", "\u64ad\u653e");
            g(ControUtils.musicDom.cover, "play");
            h(ControUtils.musicDom.cover, "paused")
        },
        getRandomIndex: function() {
            var a = ControUtils.currentMusic,
            c = ControUtils.musicLength,
            b = 0,
            d = [];
            for (b; c > b; b++) b != a && d.push(b);
            a = parseInt(Math.random() * d.length);
            return d[a]
        },
        playByMode: function(a) {
            var c = ControUtils.playMode,
            b = ControUtils.currentMusic;
            if(ControUtils.config.musicList!=undefined&&ControUtils.config.musicList!=null&&ControUtils.config.musicList.length<b){
            	ControUtils.currentMusic=0;
            	b=0;
            };
            var d = ControUtils.musicLength,
            e = b;
            1 == c ? "prev" == a ? e = d - 1 >= b && 0 < b ? b - 1 : d - 1 : ("next" == a || "ended" == a) && (e = b >= d - 1 ? 0 : b + 1) : 2 == c ? e = ControUtils.getRandomIndex() : 3 == c && (e = "prev" == a ? d - 1 >= b && 0 < b ? b - 1 : d - 1 : "next" == a ? b >= d - 1 ? 0 : b + 1 : b);
            
            ControUtils.resetPlayer(e)
        },
        action: function() {
            var a = ControUtils,
            c = ControUtils.musicDom.volume,
            b = ControUtils.musicDom.button;
            ControUtils.audioDom.addEventListener("timeupdate",
            function() {
                if (!isNaN(this.duration)) {
                    var b = n(this.currentTime),
                    c = n(this.duration),
                    d = this.currentTime / this.duration * a.musicDom.bufferProcess.parentNode.offsetWidth;
                    a.musicDom.time.innerHTML = "" + b + "/" + c;
                    a.musicDom.curProcess.style.width = d + "px";
					time=this.currentTime;
				}
            },
            !1);
            ControUtils.audioDom.addEventListener("ended",
            function() {
                a.playByMode("ended")
            },
            !1);
            c.volumeControl.addEventListener("click",
            function(b) {
                b = b || window.event;
                b.stopPropagation();
                k(c.volumeProcess, "show") ? (k(this, "muted") ? g(this, "muted") : h(this, "muted"), a.audioDom.muted = k(this, "muted") ? !0 : !1) : h(c.volumeProcess, "show")
            },
            !1);
            document.addEventListener("click",
            function(a) {
                a = a || window.event;
                a.stopPropagation();
                a = a.target || a.srcElement;
                a.parentNode !== c.volumeProcess && a.parentNode !== f(".grid-music-container .u-volume") && g(c.volumeProcess, "show")
            },
            !1);
            c.volumeEventer.addEventListener("click",
            function(b) {
                b = b || window.event;
                b.stopPropagation();
                var c = this.offsetHeight;
                a.setVolume((c - b.offsetY) / c)
            },
            !1);
            var d = document.querySelectorAll(".m-music-list-wrap li"),
            e = 0;
            for (e; e < ControUtils.musicLength; e++) !
            function(b) {
                d[b].addEventListener("click",
                function() {
                    a.resetPlayer(b)
                },
                !1)
            } (e);
            b.ctrl.addEventListener("click",
            function() {
                k(this, "play") ? a.pause() : a.play()
            },
            !1);
            b.prev.addEventListener("click",
            function() {
                a.playByMode("prev")
            },
            !1);
            b.next.addEventListener("click",
            function() {
                a.playByMode("next")
            },
            !1);
            b.listCircular.addEventListener("click",
            function() {
                h(this, "current");
                g(b.singleCircular, "current");
                g(b.randomPlay, "current");
                a.playMode = 1
            });
            b.randomPlay.addEventListener("click",
            function() {
                h(this, "current");
                g(b.singleCircular, "current");
                g(b.listCircular, "current");
                a.playMode = 2
            });
            b.singleCircular.addEventListener("click",
            function() {
                h(this, "current");
                g(b.listCircular, "current");
                g(b.randomPlay, "current");
                a.playMode = 3
            })
        },
        init: function() {
            ControUtils.musicDom = {
                music: f(".grid-music-container"),
                cover: f(".grid-music-container .u-cover"),
                title: f(".grid-music-container .u-music-title"),
                curProcess: f(".grid-music-container .current-process"),
                bufferProcess: f(".grid-music-container .buffer-process"),
                time: f(".grid-music-container .u-time"),
                listWrap: f(".grid-music-container .m-music-list-wrap"),
                volume: {
                    volumeProcess: f(".grid-music-container .volume-process"),
                    volumeCurrent: f(".grid-music-container .volume-current"),
                    volumeCtrlBar: f(".grid-music-container .volume-bar"),
                    volumeEventer: f(".grid-music-container .volume-event"),
                    volumeControl: f(".grid-music-container .volume-control")
                },
                button: {
                    ctrl: f(".grid-music-container .ctrl-play"),
                    prev: f(".grid-music-container .prev"),
                    next: f(".grid-music-container .next"),
                    listCircular: f(".grid-music-container .mode-list"),
                    randomPlay: f(".grid-music-container .mode-random"),
                    singleCircular: f(".grid-music-container .mode-single")
                }
            };
            ControUtils.currentMusic = ControUtils.config.randomIndex || 2;
            ControUtils.playMode = 2;
            var children=null;
            if(document.getElementsByTagName("audio")==null||document.getElementsByTagName("audio")==undefined||document.getElementsByTagName("audio")[0]==null||document.getElementsByTagName("audio")[0]==undefined){
            	children=document.createElement("audio");
            	document.getElementsByTagName("body")[0].append(children);
            }else{
            	children=document.getElementsByTagName("audio")[0];
            }
            ControUtils.audioDom = children;
            ControUtils.createListDom();
            ControUtils.initPlay();
            if(firstLoad){
            	ControUtils.action()
            	firstLoad=false;
            }
        }
        
}

function h(a, c) {
    0 == k(a, c) && (a.className += " " + c)
}
function k(a, c) {
    return !! a.className.match(new RegExp("(\\s|^)" + c + "(\\s|$)"))
}
function g(a, c) {
    var b = a.className;
    k(a, c) && (b = b.replace(new RegExp("(\\s|^)" + c + "(\\s|$)"), " "), b = b.replace(/(^\s*)|(\s*$)/g, ""), a.className = b)
}
function f(a) {
    return document.querySelector(a)
}
function n(a) {
    var c, b, d, e = "";
    return c = String(parseInt(a / 3600, 10)),
    b = String(parseInt(a % 3600 / 60, 10)),
    d = String(parseInt(a % 60, 10)),
    "0" != c && (1 == c.length && (c = "0" + c), e += c + ":"),
    1 == b.length && (b = "0" + b),
    e += b + ":",
    1 == d.length && (d = "0" + d),
    e + d
}


$(
	    $("#progressBar").click(function (event) {
	        var currentProgressBar=document.querySelector('#progressBar');
	        event = event || window.event;  
	        // 2.获取鼠标在整个页面的位置
	        var pagex = event.pageX || scroll().left + event.clientX;  
	        var pagey = event.pageY || scroll().top + event.clientY;  
	        // 3.获取盒子在整个页面的位置
	        var xx = $('#progressBar').offset().left;
	        var yy = currentProgressBar.offsetTop
	        // 4.用鼠标的位置减去盒子的位置赋值给盒子的内容。
	        var targetx = pagex - xx;  
	        var targety = pagey - yy; 
	        var newCurrentTime= targetx/currentProgressBar.offsetWidth;
	        $("audio").eq(0).css("display","none");
	        var audio=$("audio")[0];
	        var time=audio.duration;
	        audio=document.getElementsByTagName("audio")[0];
	        audio.currentTime = parseInt(newCurrentTime*time);
	    })
	);